<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{$title}-{$Think.lang.web_name}</title>
    {include file="comm/header"/}
</head>
<body>
{include file="comm/left_menu"/}
{include file="comm/top_menu"/}
<div class="container main">
    <div class="col-sm-12 border-bottom text-right"><a class="btn btn-primary mgr-10" href="/Content/config_list/id/{$config._config_id}"><i class="fa fa-list-ul"></i>&nbsp;{$Think.lang.config_list}</a></div>

    <div class="col-sm-12">
        <div class="col-sm-12"> &nbsp;</div>
        <form class="form-horizontal" method="post" action="/Content/config_save/">

            <div class="form-group">
                <label class="col-sm-3 control-label">{$Think.lang.config_pid}</label>
                <div class="col-sm-3">
                    <select class="form-control" name="config_pid">
                        <option value="0">{$Think.lang.select}</option>
                        {if isset($config_pid_list)}
                        {foreach name="$config_pid_list" key="key" id="v" index="i"}
                        {if $config.config_id == $v.config_id || $v.disabled == "1"}
                        <option value="{$v.config_id}" disabled style="background: #EBECD4;">{$v.add_str|raw}{$v.config_name}</option>
                        {else}
                        <option value="{$v.config_id}" {if in_array($v.config_id,[$config.config_pid])} selected{/if}>{$v.add_str|raw}{$v.config_name}</option>
                        {/if}
                        {/foreach}
                        {/if}
                    </select>
                </div>
                <small class="col-sm-4 form-tips"></small>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">{$Think.lang.config_name}</label>
                <div class="col-sm-3">
                    <input class="form-control" name="config_name" value="{$config.config_name}" required>
                </div>
                <small class="col-sm-4 form-tips"></small>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">{$Think.lang.config_url}</label>
                <div class="col-sm-3">
                    <input class="form-control" name="config_url" value="{$config.config_url}" placeholder="格式: controller/action">
                </div>
                <small class="col-sm-4 form-tips"></small>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">{$Think.lang.config_order}</label>
                <div class="col-sm-3">
                    <input type="number" class="form-control" name="config_order" value="{if $config.config_order}{$config.config_order}{else}0{/if}">
                </div>
                <small class="col-sm-4 form-tips"></small>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">{$Think.lang.config_desc}</label>
                <div class="col-sm-3">
                    <textarea name="config_desc" class="form-control" rows="5" placeholder="250字以内">{$config.config_desc}</textarea>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">{$Think.lang.config_img}</label>
                <!--KindEditor 图片上传预览部分-->
                <div class="col-sm-9">
                    <div class="s-div-img-preview" style="display: none">
                        <!--<div class="s-div-img-item">
                            <img src="" id="img1">
                            <i class="fa fa-times" aria-hidden="true" ele="close"></i>
                            <input type="hidden" id="url1" name="meida_imgs[]"  value="">
                        </div>-->
                        {foreach name="config_img_list" key="key" id="v" index="i"}
                        <div class="s-div-img-item">
                            <img src="{$v}">
                            <i class="fa fa-times" aria-hidden="true" ele="close"></i>
                            <input type="hidden"  name="meida_imgs[]"  value="{$v}">
                        </div>
                        {/foreach}
                    </div>
                    <div class="s-div-img-upload">
                        <input type="button" class="btn btn-default" id="images_up_btn" value="选择图片">
                    </div>
                    <script type="text/javascript">
                        var iele = $("i[ele='close']");
                        (iele.length>0)&&(iele[0].parentNode.parentNode.style.display="");
                        iele.one("click",function () {
                            var img_preview = this.parentNode.parentNode;
                            img_preview.removeChild(this.parentNode);
                            //iele.unbind("click");
                            $(this).unbind("click");
                        });
                    </script>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">{$Think.lang.config_extend}</label>
                <div class="col-sm-3">
                    <textarea name="config_extend" id="config_extend" class="form-control" rows="5">{$config.config_extend}</textarea>
                </div>
                <small class="col-sm-4 form-tips"></small>
            </div>
            <div class="form-group">
                <style type="text/css">
                    .config_extend-div{
                        margin-bottom: 10px;float: left;width: 45%;height: 30px;line-height:30px;text-align: center;box-sizing: border-box;
                    }
                    .config_extend-div>.form-control{
                        width: 95%;
                    }
                    .config_extend-div_1{
                        float: left;width: 10%;box-sizing: border-box;
                    }
                </style>
                <label class="col-sm-3 control-label">添加扩展信息</label>
                <div class="col-sm-8">
                    <div class="config_extend-div" >键名</div>
                    <div class="config_extend-div">键值</div>
                    <div class="config_extend-div_1"><a href="javascript:add_config_ext();" class="btn btn-primary mgr-10">添加</a></div>
                    <div style="width: 100%;" id="add_config_ext">

                    </div>
                    <div class="col-sm-12"><a href="javascript:save_config_ext();" class="btn btn-primary">保存扩展信息</a></div>
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-3 control-label">{$Think.lang.config_status}</label>
                <div class="col-sm-3">
                    <label class="s-label-radio">
                        <input type="radio" name="config_status" value="0" id="config_status_0" {if in_array($config.config_status,[0])} checked {/if}>
                        <label for="config_status_0" class="fa fa-check"></label>{$Think.lang.config_status_0}
                    </label>
                    <label class="s-label-radio">
                        <input type="radio" name="config_status" value="1" id="config_status_1" {if in_array($config.config_status,[1,''])} checked {/if}>
                        <label for="config_status_1" class="fa fa-check"></label>{$Think.lang.config_status_1}
                    </label>
                </div>
                <small class="col-sm-4 form-tips"></small>
            </div>




            <div class="form-group">
                <label class="col-sm-3 control-label"></label>
                <div class="col-sm-3">
                    <input type="hidden" name="config_id" value="{$config.config_id}">
                    <input type="hidden" name="token" value="">
                    <button class="btn btn-primary" type="submit">提交保存</button>
                </div>
                <small class="col-sm-4 form-tips"></small>
            </div>

        </form>
    </div>
</div>
{include file="comm/footer"/}
<script type="text/javascript">

</script>
<script type="text/javascript">
    //扩展信息部分操作
    function init_config_ext() {
        var config_extend = $("#config_extend");
        var data = config_extend.val();
        try {
            data = $.parseJSON(data);
        }catch (e) {}
        var html="";
        if (is_object(data) || is_array(data)) {
            for (var attr in data){
                html+="<div>\n" +
                    "                            <div class=\"config_extend-div\"><input class=\"form-control\" value="+attr+" data-name=\"key\"></div>\n" +
                    "                            <div class=\"config_extend-div\"><input class=\"form-control\" value="+data[attr]+" data-name=\"value\"></div>\n" +
                    "                            <div class=\"config_extend-div_1\"><a href=\"javascript:;\" onclick=\"del_config_ext(this)\" class=\"btn btn-primary mgr-10\">删除</a></div>\n" +
                    "                        </div>";
            }
        }
        $("#add_config_ext").append(html)
    }
    function add_config_ext() {
        var html="<div>\n" +
            "                            <div class=\"config_extend-div\"><input class=\"form-control\" data-name=\"key\"></div>\n" +
            "                            <div class=\"config_extend-div\"><input class=\"form-control\" data-name=\"value\"></div>\n" +
            "                            <div class=\"config_extend-div_1\"><a href=\"javascript:;\" onclick=\"del_config_ext(this)\" class=\"btn btn-primary mgr-10\">删除</a></div>\n" +
            "                        </div>";
        $("#add_config_ext").append(html);
    }
    function save_config_ext() {
        var keys = $("input[data-name=key]");
        var values = $("input[data-name=value]");
        var arr={};
        for (var i=0,len=keys.length;i<len;i++){
            if (keys[i].value && values[i].value){
                arr[keys[i].value] = values[i].value;
            }
        }
        $("#config_extend").val(JSON.stringify(arr));
    }
    function del_config_ext(o) {
        o.onclick=null;
        o.parentNode.parentNode.parentNode.removeChild(o.parentNode.parentNode);
    }
    init_config_ext();
</script>
</body>
</html>